package com.example.orderserver.controller;

import com.example.orderserver.entity.Order;
import com.example.orderserver.feign.ProductApi;
import com.example.orderserver.service.IOrderService;
import com.example.productserver.entity.Product;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author whx
 * @date 2022/4/3
 */
@RestController
@AllArgsConstructor
@Api(value = "订单Controller", tags = "订单接口")
public class OrderController {
    private final IOrderService orderService;
    private final ProductApi productApi;

    @ApiOperation(value = "列表", notes = "无参数")
    @GetMapping("list")
    public List<Order> list(){
        return orderService.list();
    }

    @ApiOperation(value = "商品列表", notes = "无参数")
    @GetMapping("listProduct")
    public List<Product> listProduct(){
        return productApi.list();
    }

    @ApiOperation(value = "新增/修改", notes = "无参数")
    @GlobalTransactional
    @PostMapping("save")
    public String save(){
        Order order = new Order();
        order.setId(555L);
        order.setOrderNo("DD001");
        order.setCreateTime(new Date());
        orderService.save(order);
        return productApi.save();
    }

}
